<template>
	<view class="goods_bgcolor">
		<goods-list :goods='goods' @goodsClick='goGoodsDetail'></goods-list>
		<view class="isOver" v-if="flag">
			---到底了---
		</view>
	</view>
</template>

<script>
	import goodsList1 from "../components/goods-list/goods-list.vue"
	export default {
		data() {
			return {
				pageindex:1,
				goods:[],
				flag:false,
			}
		},
		onLoad(){
			this.getHotGoods()
		},
		
		components:{"goods-list":goodsList1},
		methods: {
			async getHotGoods(acllback){
				const res=await this.$myRequest({
					url:'/api/getgoods?pageindex='+this.pageindex
				})
				this.goods = [...this.goods,...res.data.message]
				acllback&&acllback()
			},
			goGoodsDetail(id){
				uni.navigateTo({
					url:'../goodsDetail/goodsDetail?id='+id
				})
			}
		},
		onReachBottom() {
			console.log(this.goods.length)
			if(this.goods.length<this.pageindex*10) return this.flag=true
			this.pageindex++
			this.getHotGoods()
		},
		/* 监听下拉刷新 */
		onPullDownRefresh() {
			console.log('下拉l')
			this.pageindex=1
			this.goods=[]
			this.flag=false
			setTimeout(()=>{
				this.getHotGoods(()=>{
					uni.stopPullDownRefresh()
				})
			},1000)
			
		}
		
	}
</script>

<style lang="scss">
.goods_bgcolor{
	background-color: #eee;
	padding-top: 15rpx;
}
.isOver{
	width: 100%;
	height: 50px;
	line-height: 50px;
	
	font-size: 28rpx;
	text-align: center;
}
</style>
